package com.seasonsfood.mall.service.dispatch.service.impl;

import javax.annotation.Resource;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageInfo;
import com.seasonsfood.mall.core.service.impl.BaseServiceImpl;
import com.seasonsfood.mall.service.dispatch.api.domain.DispCircuit;
import com.seasonsfood.mall.service.dispatch.api.service.DispCircuitService;
import com.seasonsfood.mall.service.dispatch.mapper.DispCircuitMapper;
import com.seasonsfood.mall.util.model.ListResponse;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

@Component
@Service(interfaceClass = DispCircuitService.class)
public class DispCircuitServiceImpl extends BaseServiceImpl<DispCircuit> implements DispCircuitService {
    @Resource
    DispCircuitMapper dispCircuitMapper;

    @Override
    public ListResponse<DispCircuit> chooseCircuit(String circuitName, Long dispatchId) {
        Example example = new Example(DispCircuit.class);
        Example.Criteria criteria = example.createCriteria();
        if (circuitName != null) {
            criteria.andLike("circuitName", circuitName);
        }
        if (dispatchId != null) {
            criteria.andEqualTo("dispatchId", dispatchId);
        }
        PageInfo<DispCircuit> pageInfo = new PageInfo<>(dispCircuitMapper.selectByExample(example));
        ListResponse<DispCircuit> listResponse = new ListResponse<>(pageInfo);
        return listResponse;

    }
}
